package com.example.qxglxt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.example.qxglxt.dao.IRolesDao;
import com.example.qxglxt.model.Roles;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/role")
public class RolesController {
    @Resource
    private IRolesDao rolesDao;

    @ApiOperation(value = "查询所有角色",notes = "查询所有角色")
    @GetMapping("/findAll")
     public Map<String ,Object> findAll(){
        List<Roles> list=rolesDao.findAll();
        Map<String ,Object> map=new HashMap<String ,Object>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", list.size());
        map.put("data", list);
        return map;
    } 
    @ApiOperation(value = "添加角色",notes = "修改角色")
    @PostMapping("/addOredit")
    public Roles addRole(@RequestBody Roles r){
        return rolesDao.save(r);
    }
    @ApiOperation(value = "删除角色",notes = "删除角色")
    @ApiImplicitParam(name = "id",value = "角色编号",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void delRole(@PathVariable Integer id){
        rolesDao.deleteById(id);
    }
}